& (Bitwise AND)

The Bitwise AND operator performs the Boolean AND operation on the two whole numbers given. The numbers are converted to their 32 bit binary equivelants, then evaluated. The result, given as a whole decimal number (an integer), is then returned from the operation. The AND operation follows the following rules.

• A One and a Zero, evaluated, returns a zero.

• A Zero and a One, evaluated, returns a zero.

• A Zero and a Zero, evaluated, returns a zero.

• A One and a One, evaluated, returns a one.

You can see that it is a fairly simple operation. The difficulty comes into play when you use the 32 bit binary representation of the decimal number. The computer does all the work for you. The explanation was given to give you an idea as to what happens when using this operator.

syntax:

numberOne & numberTwo

EXAMPLE

variableOne = 15 & 20;

document.write("The sum of the AND operation is " + variableOne);

The variableOne variable contains the Bitwise AND operator, which evaluates the AND operation on the numebrs 15 and 20. The document.write statement displays the answer of 4.